package com.lxmes.common.utils;


import com.alibaba.fastjson.JSONObject;
import com.aliyun.dysmsapi20170525.models.*;
import com.aliyun.teaopenapi.models.*;

public class Sample {

        /**
         * 使用AK&SK初始化账号Client
         * @param accessKeyId
         * @param accessKeySecret
         * @return Client
         * @throws Exception
         * 张志煜
         */
        public static com.aliyun.dysmsapi20170525.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
            Config config = new Config()
                    // 您的AccessKey ID
                    .setAccessKeyId(accessKeyId)
                    // 您的AccessKey Secret
                    .setAccessKeySecret(accessKeySecret);
            // 访问的域名
            config.endpoint = "dysmsapi.aliyuncs.com";
            return new com.aliyun.dysmsapi20170525.Client(config);
        }
    public static String sendSms(String phone,String product,String code) throws Exception {
        com.aliyun.dysmsapi20170525.Client client = Sample.createClient("LTAI5tJ9e8p8rAM66NtbdNKf", "JjezWobuuI1rXAMb7mlDoLrDQQwEZM");
        JSONObject object =new JSONObject();
        object.put("product",product);
        SendSmsRequest sendSmsRequest = new SendSmsRequest();
        sendSmsRequest.setSignName("蓝象设备云维保");
        sendSmsRequest.setPhoneNumbers(phone);
        sendSmsRequest.setTemplateCode(code);
        sendSmsRequest.setTemplateParam(object.toJSONString());
        SendSmsResponse response = client.sendSms(sendSmsRequest);
        return response.body.getCode();
    }
        public static void main(String[] args_) throws Exception {
            java.util.List<String> args = java.util.Arrays.asList(args_);
            com.aliyun.dysmsapi20170525.Client client = Sample.createClient("LTAI5tJ9e8p8rAM66NtbdNKf", "JjezWobuuI1rXAMb7mlDoLrDQQwEZM");
            JSONObject object =new JSONObject();
            object.put("product","SBWX202205101123");
            SendSmsRequest sendSmsRequest = new SendSmsRequest();
            sendSmsRequest.setSignName("蓝象设备云维保");
            sendSmsRequest.setPhoneNumbers("18615626509");
            sendSmsRequest.setTemplateCode("SMS_241057261");
            sendSmsRequest.setTemplateParam(object.toJSONString());
            // 复制代码运行请自行打印 API 的返回值
            SendSmsResponse response = client.sendSms(sendSmsRequest);
            System.out.println(response.body.getCode());
        }

}

